import { OrgModel } from '@/api/manager/organize/interface'
import { groupBy } from 'lodash-es'

export const orgMtSort = (mtList: OrgModel[]) => {
	/**先按照会议层级分组 */
	let _result = []
	let conf_level_group = groupBy(mtList, (item) => item.mcc.confLevel) || {}
	if (conf_level_group && conf_level_group['2'] && conf_level_group['2'].length > 0) {
		let x = conf_level_group['2'].sort((a, b) => a.mcc.index - b.mcc.index)
		_result.push(...x)
	}
	if (conf_level_group && conf_level_group['3'] && conf_level_group['3'].length > 0) {
		/**进行e164号分组 */
		let x = conf_level_group['3'].sort(
			(a, b) =>
				+a.mcc.confE164 - +b.mcc.confE164 ||
				a.mcc.index - b.mcc.index ||
				Number(a.mcc.mtKey.split('_').pop()) - Number(b.mcc.mtKey.split('_').pop())
		)
		_result.push(...x)
	}
	return _result
}
